package com.liuc.practice.server.servlet;

import com.liuc.practice.server.pojo.Request;
import com.liuc.practice.server.pojo.Response;
import com.liuc.practice.server.util.HttpProtocolResponseUtil;

import java.io.IOException;
import java.io.PrintStream;

/**
 * @Author Liu Chang
 * @Date 2021/7/22 11:05 下午
 */
public class MyServlet extends HttpServlet {
    @Override
    public void doGet(Request request, Response response) throws IOException, InterruptedException {
//        Thread.sleep(30000);
        String content = "<h1> GET <h1>";
        PrintStream out = System.out;
        out.println(content);
        response.output(HttpProtocolResponseUtil.successHeader(content.getBytes().length) + content);
    }

    @Override
    public void doPost(Request request, Response response) throws IOException {
        String content = "<h1> POST <h1>";
        response.output(HttpProtocolResponseUtil.successHeader(content.getBytes().length) + content);
    }

    @Override
    public void init() throws Exception {

    }

    @Override
    public void destroy() throws Exception {

    }
}
